﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;

namespace JqueryNet.FormControl.FormWebControl
{
    public class JImageButton : JWebControl
    {
        ImageButton imageButton;
        public JImageButton(ImageButton imageButton)
            : base(imageButton)
        {
            this.imageButton = imageButton;
        }

        public override void Attr(string key)
        {
            switch (key.ToLower())
            {
                case "alt":
                case "alternatetext":
                    Value = imageButton.AlternateText;
                    return;
                case "descriptionurl":
                case "longdesc":
                    Value = imageButton.DescriptionUrl;
                    return;
                case "generateemptyalternatetext":
                    Value = imageButton.GenerateEmptyAlternateText;
                    return;
                case "height":
                    Value = imageButton.Height;
                    return;
                case "imagealign":
                    Value = imageButton.ImageAlign;
                    return;
                case "imageurl":
                    Value = imageButton.ImageUrl;
                    return;
                case "width":
                    Value = imageButton.Width;
                    return;
                case "tooltip":
                case "title":
                    Value = imageButton.ToolTip;
                    return;
                case "cssclass":
                case "css":
                case "class":
                    Value = imageButton.CssClass;
                    return;
                default:
                    base.Attr(key); return;
            }
        }

        public override void Attr(string key, string value)
        {
            int b;
            int.TryParse(value, out b);
            bool f;
            bool.TryParse(value, out f);
            switch (key.ToLower())
            {
                case "alt":
                case "alternatetext":
                    imageButton.AlternateText = value;
                    return;
                case "descriptionurl":
                case "longdesc":
                    imageButton.DescriptionUrl = value;
                    return;
                case "generateemptyalternatetext":
                    imageButton.GenerateEmptyAlternateText = f;
                    return;
                case "height":
                    imageButton.Height = b;
                    return;
                case "imagealign":
                    imageButton.ImageAlign = (ImageAlign)Enum.Parse(typeof(ImageAlign), value, false);
                    return;
                case "imageurl":
                    imageButton.ImageUrl = value;
                    return;
                case "width":
                    imageButton.Width = b;
                    return;
                case "tooltip":
                case "title":
                    imageButton.ToolTip = value;
                    return;
                default:
                    base.Attr(key, value); return;
            }
        }

        public override void Val()
        {
            Value = imageButton.ImageUrl;
        }

        public override void Val(string value)
        {
            imageButton.ImageUrl = value;
        }
    }
}
